//
//  JMBCouponManagerVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/8/7.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "JMBCouponManagerVC.h"
#import "JMBCouponDoingVC.h"
#import "JMBCouponFinishedVC.h"
#import "NSString+JMExtension.h"
#import "JMBCouponAddVC.h"
@interface JMBCouponManagerVC ()
@property (nonatomic,strong) NSMutableArray *titleArray;
@end

@implementation JMBCouponManagerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _addUI];
    [self _setupNavigationItem];
}

- (void)_addUI{
    self.magicView.navigationColor = [UIColor whiteColor];
    self.magicView.sliderColor = UIColorHex(6DBE2F);
    self.magicView.separatorHeight = 0.0;
    self.magicView.sliderHeight = 1.0;
    self.magicView.layoutStyle = VTLayoutStyleCenter;
    self.magicView.itemSpacing = UI_SCREEN_WIDTH *0.192;
    self.magicView.switchStyle = VTSwitchStyleDefault;
    self.magicView.navigationHeight = 38.f;
    self.magicView.dataSource = self;
    self.magicView.delegate = self;
    self.titleArray = [NSMutableArray arrayWithArray:@[JMLocalStr(@"进行中"),JMLocalStr(@"已结束")]];
    [self.magicView reloadData];
    
}
#pragma mark - 设置导航栏
- (void)_setupNavigationItem{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(_shuffle:)];
}
#pragma mark - 事件处理Or辅助方法
- (void)_shuffle:(UIBarButtonItem *)sender{
    NSLog(@"添加优惠券");
    JMBCouponAddVC *vc = [[JMBCouponAddVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView
{
    return self.titleArray;
}
- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex
{
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:UIColorHex(B2B2B2) forState:UIControlStateNormal];
        [menuItem setTitleColor:UIColorHex(6DBE2F) forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return menuItem;
}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex{
    if (0 == pageIndex) {
        static NSString *doingId = @"doing.identifier";
        JMBCouponDoingVC *doingVC = [magicView dequeueReusablePageWithIdentifier:doingId];
        if (!doingVC) {
            doingVC = [[JMBCouponDoingVC alloc] init];
        }
        return doingVC;
    }
    static NSString *finishedId = @"finished.identifier";
    JMBCouponFinishedVC *finishedVC = [magicView dequeueReusablePageWithIdentifier:finishedId];
    if (!finishedVC) {
        finishedVC = [[JMBCouponFinishedVC alloc] init];
    }
    return finishedVC;
}
- (CGFloat)magicView:(VTMagicView *)magicView sliderWidthAtIndex:(NSUInteger)itemIndex {
    NSString *itemStr = self.titleArray[itemIndex];
    CGFloat itemStrWidth = [itemStr jm_sizeWithFont:[UIFont systemFontOfSize:15]].width;
    return  itemStrWidth;
}

- (NSMutableArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSMutableArray array];
    }
    return _titleArray;
}
@end
